﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;

namespace DARE
{
    /// <summary>
    /// This renderer manages everything that concerns 2D scenes.
    /// This is where you have to register your 2D entities that you want to display.
    /// </summary>
    public class CRender2D : ARenderable
    {
        #region fields

        private Dictionary<string, AEntity> m_entities;
        private SpriteBatch m_spriteBatch;
        private CScene m_scene;

        #endregion

        #region properties

        public CScene Scene { get { return m_scene; } set { m_scene = value; } }

        #endregion

        #region ctor

        public CRender2D(string renderName)
        {
            m_name = renderName;
            this.m_spriteBatch = CDare.Instance.SpriteBatch;
            m_entities = new Dictionary<string, AEntity>();
        }

        #endregion

        #region methods

        public CRender2D RegisterEntity(AEntity entity)
        {
            m_entities.Add(entity.Name, entity);
            return this;
        }

        public CRender2D UnregisterEntity(AEntity entity)
        {
            m_entities.Remove(entity.Name);
            return this;
        }

        public override void Update(Microsoft.Xna.Framework.GameTime gameTime)
        {
            foreach (AEntity entity in m_entities.Values)
                entity.Update(gameTime);
        }

        public override void Draw(Microsoft.Xna.Framework.GameTime gameTime)
        {
            m_spriteBatch.Begin();
            foreach (AEntity entity in m_entities.Values)
                entity.Draw(gameTime);
            m_spriteBatch.End();
        }

        #endregion
    }
}
